#include<iostream>
using namespace std;

bool is_prime(int n){
	if(n<=1){
		return false;
	}
	for(int i=2;i*i<=n;i++){
		if(n%i==0)return false;
	} 
	return true;
} 


void solve(){
	int x,k;
	cin>>x>>k;
	if(k>1&&x>1){
		cout<<"NO"<<endl;
	}
	else if(k==1){
		cout<<(is_prime(x)?"YES":"NO")<<endl;
	}
	else{
		cout<<((k==2)?"YES":"NO")<<endl; 
	}
	return ;
}

int main(){
	int t;
	cin>>t;
	while(t--){
		solve();
	}
	return 0;
}
